/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ages.graphics;
import com.sun.opengl.util.j2d.TextRenderer;
import java.awt.Font;
import javax.media.opengl.GL;

/**
 *
 * @author felix
 */
public class FPSRenderer {
    
    private int width,height;
    public static TextRenderer renderer;
    private int fps;
    private int frameCounter = 0;
    private int score = 0;
    private double lastFrame = System.currentTimeMillis();


    public FPSRenderer(int width, int height)
    {
        this.width = width;
        this.height = height;
        renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 16),true,true);
    }
    
    public void draw(GL gl)
    {

        frameCounter++;
        if((System.currentTimeMillis()-lastFrame)>=1000)
        {
        fps = frameCounter;
        lastFrame = System.currentTimeMillis();
        frameCounter = 0;
        }
        
        

        TextRenderHack.fixIt(renderer);
        renderer.beginRendering(width, height);
        renderer.setColor(0.06f,0.06f,0.06f, 1f);
        renderer.draw("FPS: "+fps,10,10);
        renderer.setColor(0.9f,0.9f,0.9f, 1f);
        renderer.draw("FPS: "+fps,12,12);
        renderer.endRendering();
    }
    
}
